import request from "../request.js";

/**
 * 确认支付
 * @param {Object} data - 支付相关数据
 * @returns {Promise}
 */
export function pay(data) {
  return request({
    url: "/api/order/pay",
    method: "post",
    data,
  });
}

/**
 * 取消支付
 * @param {Object} data - 取消支付相关数据
 * @returns {Promise}
 */
export function cancel_pay(data) {
  return request({
    url: "/api/order/cancel_pay",
    method: "post",
    data,
  });
}

/**
 * 获取我的订单列表
 * @param {Object} data - 查询参数
 * @param {number} [data.user_id] - 用户ID
 * @param {number} [data.status] - 订单状态（不传则获取所有状态）
 * @returns {Promise}
 */
export function getOrderList(data) {
  return request({
    url: "/api/order",
    method: "get",
    params: data,
  });
}

/**
 * 删除订单(状态1,2,3,6不可删)
 * @param {Object} data - 删除订单所需数据
 * @param {number} data.order_id - 订单ID
 * @returns {Promise}
 */
export function deleteOrder(data) {
  return request({
    url: "/api/order/del",
    method: "post",
    data,
  });
}

/**
 * 申请退款
 * @param {Object} data - 退款相关数据
 * @param {number} data.order_id - 订单ID
 * @param {string} data.reason - 退款原因
 * @returns {Promise}
 */
export function applyRefund(data) {
  return request({
    url: "/api/order/refund",
    method: "post",
    data,
  });
}

/**
 * 取消订单
 * @param {Object} data - 取消订单相关数据
 * @param {number} data.order_id - 订单ID
 * @param {string} [data.reason] - 取消原因
 * @returns {Promise}
 */
export function cancelOrder(data) {
  return request({
    url: "/api/order/cancel",
    method: "post",
    data,
  });
}

/**
 * 确认收货
 * @param {Object} data - 确认收货相关数据
 * @param {number} data.order_id - 订单ID
 * @returns {Promise}
 */
export function confirmReceipt(data) {
  return request({
    url: "/api/order/verify",
    method: "post",
    data,
  });
}

/**
 * 待付款订单支付
 * @param {Object} data - 支付相关数据
 * @returns {Promise}
 */
export function payPendingOrder(data) {
  return request({
    url: "/api/order/order_pay",
    method: "post",
    data,
  });
}
